<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Test Summary Component</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            margin: 20px;
            background-color: #f5f5f5;
        }
        .container {
            max-width: 800px;
            margin: 0 auto;
            background: white;
            padding: 20px;
            border-radius: 8px;
            box-shadow: 0 2px 10px rgba(0,0,0,0.1);
        }
        .summary-item {
            border: 1px solid #ddd;
            margin: 10px 0;
            padding: 15px;
            border-radius: 5px;
            background: #f9f9f9;
        }
        .summary-header {
            display: flex;
            justify-content: space-between;
            margin-bottom: 10px;
            font-size: 14px;
            color: #666;
        }
        .summary-content {
            font-size: 16px;
            line-height: 1.5;
            color: #333;
        }
        .button {
            background: #007bff;
            color: white;
            border: none;
            padding: 10px 20px;
            border-radius: 5px;
            cursor: pointer;
            margin: 10px 5px;
        }
        .button:hover {
            background: #0056b3;
        }
        .loading {
            text-align: center;
            color: #666;
            font-style: italic;
        }
        .error {
            color: #dc3545;
            text-align: center;
        }
    </style>
</head>
<body>
    <div class="container">
        <h1>Conversation Summary Test</h1>
        <p>Testing API: <code>/api/v1/chat/conversation/15/summaries</code></p>
        
        <button class="button" onclick="testSummaryAPI()">Load Summaries</button>
        <button class="button" onclick="clearResults()">Clear</button>
        
        <div id="results"></div>
    </div>

    <script>
        async function testSummaryAPI() {
            const resultsDiv = document.getElementById('results');
            resultsDiv.innerHTML = '<div class="loading">Loading summaries...</div>';
            
            try {
                const response = await fetch('/api/v1/chat/conversation/15/summaries');
                
                if (!response.ok) {
                    throw new Error(`HTTP error! status: ${response.status}`);
                }
                
                const data = await response.json();
                console.log('API Response:', data);
                
                if (data.summaries && data.summaries.length > 0) {
                    let html = `<h2>Found ${data.summaries.length} summaries:</h2>`;
                    
                    data.summaries.forEach((summary, index) => {
                        html += `
                            <div class="summary-item">
                                <div class="summary-header">
                                    <span>Messages ${summary.start_message_seq}-${summary.end_message_seq} | Type: ${summary.summary_type}</span>
                                    <span>${new Date(summary.created_at).toLocaleString()}</span>
                                </div>
                                <div class="summary-content">
                                    ${summary.summary_content}
                                </div>
                            </div>
                        `;
                    });
                    
                    resultsDiv.innerHTML = html;
                } else {
                    resultsDiv.innerHTML = '<div class="error">No summaries found</div>';
                }
                
            } catch (error) {
                console.error('Error:', error);
                resultsDiv.innerHTML = `<div class="error">Error: ${error.message}</div>`;
            }
        }
        
        function clearResults() {
            document.getElementById('results').innerHTML = '';
        }
        
        // Auto-load on page load
        window.onload = function() {
            testSummaryAPI();
        };
    </script>
</body>
</html>